package com.yl.auth.controller;

import com.yl.auth.entity.Wcshenqing;
import com.yl.auth.model.vo.WcshenqingVo;
import com.yl.auth.service.WcshenqingService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.time.LocalDateTime;

import java.util.List;

@Api(tags = "小程序-养老护理-外出登记")
@RestController
@RequestMapping("/admin/xiaochengwcdengji")
public class Xiaochengxuwcdengji {
    @Resource
    private WcshenqingService wcshenqingService;

    @GetMapping("/getxiaowcgengji")
    @ApiOperation(value = "获取全部外出登记信息,也可以根据登记状态查询")
    public Result getxiaowcgengji(@ApiParam("登记状态") Integer djzhuangtai) {
        List<WcshenqingVo> wcshenqingVo = wcshenqingService.getxiaowcgengji(djzhuangtai);
        return Result.ok(wcshenqingVo);
    }

    @GetMapping("/getxiaowcxiangqing/{id}")
    @ApiOperation(value = "小程序根据id获取外出详情")
    public Result getxiaowcxiangqing(@PathVariable @ApiParam("外出申请id") Integer id) {
        WcshenqingVo wcshenqingVo = wcshenqingService.getxiaowcxiangqing(id);
        return Result.ok(wcshenqingVo);
    }

    @GetMapping("/getxiaowchuixian/{id}")
    @ApiOperation(value = "小程序根据id回显信息")
    public Result getxiaowchuixian(@PathVariable @ApiParam("外出申请id") Integer id) {
        WcshenqingVo wcshenqingVo = wcshenqingService.getxiaowchuixian(id);
        wcshenqingVo.setChuangWeiBed(wcshenqingVo.getRoomNo() + "/" + wcshenqingVo.getBedNo());
        return Result.ok(wcshenqingVo);
    }

    @PutMapping("/tijiaowaicdengji")
    @ApiOperation(value = "提交外出登记")
    public Result tijiaowaicdengji(@RequestBody WcshenqingVo wcshenqingVo) {
        LocalDateTime currentDateTime = LocalDateTime.now();
        wcshenqingVo.setDjtime(currentDateTime);
        wcshenqingService.updateByIds(wcshenqingVo);
        return Result.ok();
    }
    @PutMapping("/tijiaofanhuidengji")
    @ApiOperation(value = "提交返回登记")
    public Result tijiaofanhuidengji(@RequestBody WcshenqingVo wcshenqingVo) {
        LocalDateTime currentDateTime = LocalDateTime.now();
        wcshenqingVo.setSjtime(currentDateTime);
        wcshenqingService.tijiaofanhuidengji(wcshenqingVo);
        return Result.ok();
    }

}